package t10086.Controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import t10086.Model.Entity.Robot;
import t10086.Model.Http.Response;
import t10086.Service.RobotService;

import java.util.Optional;

@RestController
@RequestMapping("/api/robot")
public class RobotController {

    private final RobotService robotService;

    @Autowired
    public RobotController(RobotService robotService) {
        this.robotService = robotService;
    }
    @GetMapping("/get")
    public Response getRobotById(@RequestParam Long serialNumber) {
        Optional<Robot> robot = robotService.getRobotBySerialNumber(serialNumber);
        Response response = new Response();
        if (robot.isPresent()) {
            response.addData("robot", robot.get());
        }else {
            response.setMessage("No robot found");
        }
        return response;
    }

}
